package com.cskaoyan.controller.promotion;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.promotion.*;

import com.cskaoyan.service.promotion.PromotionService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @Description: 广告管理
 * @Author: WD created on 2021-09-15 17:09
 * @Version:
 */

@RestController
@RequestMapping("admin/ad")
public class PosterController {
    @Autowired
    PromotionService promotionService;

    @RequiresPermissions(value ={"*","admin:category:read"},logical = Logical.OR)
    @RequestMapping("list")
    public BaseRespVo list(BaseParam param, String name, String content) {
//        ArrayList<Object> objects = new ArrayList<>();
//        objects.get(3);
        ShowPosterListVO posters = promotionService.getPosters(param, name, content);

        return BaseRespVo.ok(posters);
    }

    @RequiresPermissions(value ={"*","admin:category:create"},logical = Logical.OR)
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody CreatePosterBO promotion) {
        CreatePosterVO poster = promotionService.createPoster(promotion);
        return BaseRespVo.ok(poster);
    }


    @RequiresPermissions(value ={"*","admin:category:update"},logical = Logical.OR)
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody UpdatePoster poster) {

        UpdatePoster poster1 = promotionService.updatePoster(poster);

        return BaseRespVo.ok(poster1, "Good Job!!");

    }

    @RequiresPermissions(value ={"*"},logical = Logical.OR)
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody DeletePosterBO posterBO) {
        Integer integer = promotionService.deletePosterNotReal(posterBO);

        return BaseRespVo.ok("成功");


    }
}
